<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.trkj.com/tr1702/tags" prefix="my" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-easyui-1.5.5.6/locale/easyui-lang-zh_CN.js"/>"></script>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/default/easyui.css"/>" />
<link rel="stylesheet" type="text/css"
	href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/icon.css"/>" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定义职务</title>
	<style type="text/css">
		 
	</style>
</head>
<body>
<script type="text/javascript">
			var formatters =function(value,row,index){
				<my:g id="84"> 
				var del ="<a butn='tb_btn_del' onclick='delrow("+row.dutyId+")'></a>";
				</my:g> 
				<my:g id="83"> 
				var edit = "<a butn='tb_btn_edit' onclick='editrow("+row.dutyId+")'></a>";
				</my:g> 
				return  edit+del;
			}
			var delrow=function(dutyId){
				$.messager.confirm('提示','确定删除该项',function(v){
					if(v){
						$.post('defineduty_remove',{dutyId:dutyId},function(){
							$('#cf-defineduty-tb').datagrid('reload');
						});
					}
				});
			}
			var editrow =function(dutyId){
					$("#cf-defineduty-win").dialog("open");
					$("#cf-defineduty-ids").textbox('disable');
					var vv=$('#cf-defineduty-tb').datagrid('getSelected');
					$("#cf-defineduty-ids").textbox('setValue',vv.dutyId);
					$("#cf-defineduty-name").textbox('setValue',vv.dutyName);
					$('#cf-dycw-1').hide();
					$('#cf-dycw-2').show();
			}
			var editdialog =function(){
				$("<form method='get'>").appendTo(document.body).form({
					url:'update_duty',
					onSubmit:function(param){
						var vv=$('#cf-defineduty-tb').datagrid('getSelected');
						//alert(vv.positionId);
						param['dutyId'] =vv.dutyId;
						param['dutyName'] = $("#cf-defineduty-name").textbox('getValue');
					},
					success:function(){
						$('#cf-defineduty-tb').datagrid('reload');
						$('#cf-defineduty-win').dialog('close');
					}
				}).submit().appendTo(".abc");
			}
			$(function(){
				$("#cf-defineduty-tb").datagrid({onLoadSuccess: function(){
					$("a[butn=tb_btn_edit]").linkbutton({iconCls:'icon-edit', plain:true});
					$("a[butn=tb_btn_del]").linkbutton({iconCls:'icon-cancel', plain:true});
				}});
				$("#cf-defineduty-add").linkbutton({
					onClick : function() {
						$("#cf-defineduty-win").dialog("open");
						$("#cf-defineduty-f").form('clear');
						$("#cf-defineduty-ids").textbox('enable');
						/* parent.$('.dialog-button a:eq(0)').show();
						parent.$('.dialog-button a:eq(1)').hide(); */
						$('#cf-dycw-2').hide();
						$('#cf-dycw-1').show();
					}
				});
				$("#cf-defineduty-refresh").linkbutton({onClick:function(){
					$('#cf-defineduty-tb').datagrid('reload');
				}});
			});
	</script>
	<div class="abc"></div>
	<div id="cf-defineduty-tbs5">
		<my:g id="82"> 
   		 <a id="cf-defineduty-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true,text:'添加'"></a>
    	</my:g>
 		<a id="cf-defineduty-refresh" class="easyui-linkbutton" data-options="iconCls:'icon-reload',text:'刷新',plain:true,iconAlign:'right'"></a>
    	 <input class="easyui-searchbox" data-options="label:'搜索',width:300,labelWidth:50,prompt:'职务名称',
     	searcher:function(value,name){
	        $('#cf-defineduty-tb').datagrid('load','modaddSeslect_duty?text='+value);
     	 }">
  </div>
		<table id="cf-defineduty-tb" class="easyui-datagrid" data-options="
			url:'defineduty_pages',
			fitColumns:true,
			fit:true,
			nowrap:false,
			loading:true,
			pagination:true,
			rownumbers:true,
			singleSelect:true,
			pageSize:10,
    		pageList:[10,20,30,40,50],
			toolbar:'#cf-defineduty-tbs5',
			striped:true,
			method:'get'	
	">
		<thead>
		  <tr>
			<th data-options="field:'dutyId',width:200,align:'center'">职务编号</th>
			<th data-options="field:'dutyName',width:200,align:'center'">职务名称</th>
			<th data-options="field:'dutyCreatordate',width:200,align:'center',
				formatter:function(value){
						var date = new Date(value);
                        var y = date.getFullYear();
                        var m = date.getMonth() + 1;
                        var d = date.getDate();
                        return y + '-' +m + '-' + d;
				}">创建日期</th>
			<th data-options="field:'dutyUpdatedate',width:200,align:'center',
				formatter:function(value){
						var date = new Date(value);
                        var y = date.getFullYear();
                        var m = date.getMonth() + 1;
                        var d = date.getDate();
                        return y + '-' +m + '-' + d;
				}">最后更新</th>
			<th data-options="field:'3',width:200,align:'center',formatter:formatters">删除</th>
		  </tr>	
		</thead>
		<tbody>
		</tbody>
	</table>
<div id="cf-defineduty-win" class="easyui-dialog"data-options="width:300, height:150,
			title:'定义职务',
     		bodyCls:'insert_duty',
      		modal:true,
      		closed:true,
      		buttons:[{
	        	text:'提交',
				id:'cf-dycw-1',
	        	iconCls:'icon-ok',
        		handler:function(){
          		 $('#cf-defineduty-f').form({
            		onSubmit:function(param){
            		 //验证表单
						var cc=$('#cf-defineduty-ids').textbox('getValue');
             		 return $(this).form('validate');
            		},
	           		 success:function(v){
	              		//$.messager.alert('提示','注册成功');
	              		$('#cf-defineduty-tb').datagrid('reload');
		              		$('#cf-defineduty-win').dialog('close');
	            	}
          	    }).submit();
       		  }
      		},{
        		text:'修改',
				id:'cf-dycw-2',
				iconCls:'icon-edit',
        		handler:editdialog
			},{
        		text:'取消',
        		iconCls:'icon-cancel',
	        	handler:function(){
	          		$('#cf-defineduty-win').dialog('close');
	        	}
			}
			]">
		<form id="cf-defineduty-f" action="insert_duty" method="get">
			<div class="line">
				        <input id="cf-defineduty-ids" class="easyui-textbox" 
					data-options="label:'职务编号',width:250">
			</div>
			
			<div class="line">
				        <input id="cf-defineduty-name" class="easyui-textbox" name="dutyName"
					data-options="label:'职务名称',width:250">
			</div>
		</form>
	</div>

</body>
</html>